var scenicId,backUserId,auditStatus,provinceId,cityId,districtId,gender,organType
$(function () {
	scenicId = ly.getUrlParam("scenicId") || '';
	auditStatus=ly.getUrlParam("auditStatus") || '';
	if(auditStatus==1||auditStatus==2){
		$('#save_btn').hide()
		$('#Re-apply').show()
	}else{
		$('#save_btn').show()
		$('#Re-apply').hide()
	}
    if (scenicId) {
		$(".title span,title").html("编辑");
		request({
			url: site.gateUrl + '/back/scenicManagement/selectScenicInfoViewByIdAndAuditStatus',
			data: { 'scenicId': scenicId,'auditStatus':auditStatus },
			ajaxform: true,
			type: 'get',
			callback: function (r) {
				if (r.code == "rest.success") {
					var d = r.result;
					organType = d.organType
					gl(d.organType);
					$("#provincedata").val(d.provinceId)
					$("#citydata").val(d.cityId)
					$("#districtId").val(d.districtId)
					provinceId=d.provinceId
					cityId=d.cityId
					districtId=d.districtId
					// gender=d.gender
					$("#account").val(d.account)
					// $("#adminName").val(d.adminName)
					$("#password").val(d.password)
					$("#scenicName").val(d.scenicName)
					$("#corpName").val(d.corpName)
					$("#phone").val(d.phone)
					// $("#identityCard").val(d.identityCard)
					// $('#sexDetails').text(d.genderDisplay)
					$("#maximumCapacityForTheDay").val(d.maximumCapacityForTheDay)
					getProvince()
					gl(d.organType, 2);
					if(d.backUserId!=undefined&&d.backUserId!=null&&d.backUserId!=''){
						backUserId=d.backUserId
					}
					
					// $("#sex").getSelect({
					// 	type: "radio",
					// 	asName: "sex",
					// 	list: [
					// 		{ value: "1", display: "男" },
					// 		{ value: "2", display: "女" }
					// 	],
					// 	default: d.gender
					// });
					
					
					
				} else {
					ly.toast(r.msg);
				}
			}
		});
	} else {
		getProvince();
		gl(1, 1);
		// $("#sex").getSelect({
		// 	type: "radio",
		// 	asName: "sex",
		// 	list: [
		// 		{ value: "1", display: "男" },
		// 		{ value: "2", display: "女" }
		// 	],
		// 	default: 1
		// });
		$("body").on("click", "#organType input[name='organType']", function () {
			var value = $(this).val();
			organType = value;
			console.log(organType)
		});
	}
})
function gl(val, type) {
	if (type == '2' || type == 2) {
		$("#organType").getSelect({
			type: "radio",
			asName: "organType",
			list: [
				{ value: "1", display: "非文旅委" },
				{ value: "2", display: "文旅委" }
			],
			default: val,
			disabled: true
		});
		//z(teamId);
	} else {
		$("#organType").getSelect({
			type: "radio",
			asName: "organType",
			list: [
				{ value: "1", display: "非文旅委" },
				{ value: "2", display: "文旅委" }
			],
			default: val
		});
	}
}
//提交回到列表页
function  reviewBtn(auditStatus) {
	event.preventDefault();
	var account=$("#account").val()
	// var adminName=$("#adminName").val()
	var password=$("#password").val()
	var phone=$("#phone").val()
	// var identityCard=$("#identityCard").val()

		
	if(account==''){
		ly.toast('请输入机构账号');   
	}
	// if(adminName==''){
	// 	ly.toast('请输入文旅资源管理员姓名');
	// 	return false
	// }
	if(password==''){
		ly.toast('请输入账号密码');
		return false
	}
	// if(phone==''){
	// 	ly.toast('请输入联系电话');
	// 	return false
	// }
	// if(identityCard==''){
	// 	ly.toast('请输入身份证号');
	// 	return false
	// }  
    var urls =''+site.gateUrl+'/back/scenicManagement/auditScenic'
	request({
		url:urls ,
		data:{
            account:account,
            auditStatus:auditStatus,
            // adminName: adminName,
            // gender: gender,
            // identityCard:identityCard,
            password:password,
			phone:phone,
			organType:organType,
			scenicId: scenicId,
			unitType:2
        },
		ajaxform:false,
		type: 'post',
		callback: function(r) {
			if(r.code=="rest.success"){
				ly.alert("审核成功", function() {
                    window.history.go(-1)
                });
			}else{

			}
		}
	});
}
//提交回到列表页
$("body").on("click", "#save_btn", function () {
	event.preventDefault();
	var account=$("#account").val()
	// var adminName=$("#adminName").val()
	var password=$("#password").val()
	var scenicName=$("#scenicName").val()
	var corpName=$("#corpName").val()
	var phone=$("#phone").val()
	// var identityCard=$("#identityCard").val()
	// var gender=$("#sex input[name=sex]:checked").val();
	var districtId=$("#districtId").val()
	if(account==''){
		ly.toast('请输入机构账号');   
	}
	// if(adminName==''){
	// 	ly.toast('请输入文旅资源管理员姓名');
	// 	return false
	// }
	if(password==''){
		ly.toast('请输入账号密码');
		return false
	}
	if(scenicName==''){
		ly.toast('请输入机构名字');
		return false
	}
	if(corpName==''){
		ly.toast('请输入公司名字');
		return false
	}
	// if(phone==''){
	// 	ly.toast('请输入联系电话');
	// 	return false
	// }
	// if(identityCard==''){
	// 	ly.toast('请输入身份证号');
	// 	return false
	// }

	// if(gender==''){
	// 	ly.toast('请选择性别');
	// 	return false
	// }
	if(districtId==''){
		ly.toast('请选择区域');
		return false
	}
	var add_url
	if(auditStatus==0){
	    add_url = "mechanism-list.html";
	}else if(auditStatus==1){
		add_url = "mechanism-passed.html";
	}else if(auditStatus==2){
		add_url = "mechanism-rejected.html";
	}
	$(".form").submitForm({
		account:account,
		// adminName: adminName,
		backUserId:backUserId,
		corpName:corpName,
		districtId:districtId,
		// gender: gender,
		// identityCard:identityCard,
		password:password,
		organType:organType,
		phone:phone,
		scenicId: scenicId,
		unitType:2,
		maximumCapacityForTheDay:null,
		scenicName: scenicName,
		url: site.gateUrl + "/back/scenicManagement/insertOrUpdateScenicInfo",
		ajaxform: false,
	}, add_url); //成功后跳转的页面,可为空
	
})
//重新申请
$("body").on("click", "#Re-apply", function () {
	event.preventDefault();
	var account=$("#account").val()
	// var adminName=$("#adminName").val()
	var password=$("#password").val()
	var scenicName=$("#scenicName").val()
	var corpName=$("#corpName").val()
	var phone=$("#phone").val()
	// var identityCard=$("#identityCard").val()
	// var gender=$("#sex input[name=sex]:checked").val();
	var districtId=$("#districtId").val()
	if(account==''){
		ly.toast('请输入机构账号');   
	}
	// if(adminName==''){
	// 	ly.toast('请输入文旅资源管理员姓名');
	// 	return false
	// }
	if(password==''){
		ly.toast('请输入账号密码');
		return false
	}
	if(scenicName==''){
		ly.toast('请输入机构名字');
		return false
	}
	if(corpName==''){
		ly.toast('请输入公司名字');
		return false
	}
	// if(phone==''){
	// 	ly.toast('请输入联系电话');
	// 	return false
	// }
	// if(identityCard==''){
	// 	ly.toast('请输入身份证号');
	// 	return false
	// }
	// if(gender==''){
	// 	ly.toast('请选择性别');
	// 	return false
	// }
	if(districtId==''){
		ly.toast('请选择区域');
		return false
	}
	var add_url
	if(auditStatus==0){
	    add_url = "mechanism-list.html";
	}else if(auditStatus==1){
		add_url = "mechanism-passed.html";
	}else if(auditStatus==2){
		add_url = "mechanism-rejected.html";
	}
	$(".form").submitForm({
		account:account,
		// adminName: adminName,
		backUserId:backUserId,
		corpName:corpName,
		districtId:districtId,
		// gender: gender,
		// identityCard:identityCard,
		password:password,
		organType:organType,
		phone:phone,
		scenicId: scenicId,
		scenicName: scenicName,
		unitType:2,
		maximumCapacityForTheDay:null,
		url: site.gateUrl + "/back/scenicManagement/reapplyScenicInfo",
		ajaxform: false,
	}, add_url); //成功后跳转的页面,可为空
	
})
//查询省份
function getProvince(){
	var urls =''+site.gateUrl+'/back/areaManagement/selectAreaProvince'
	request({
		url:urls ,
		data:{},
		ajaxform:true,
		type: 'post',
		callback: function(r) {
			if(r.code=="rest.success"){
				 var lists = r.result;
				 var htmls = '';
				 for (let i = 0; i < lists.length; i++) {
					 console.log(lists[i].id,provinceId,'lists[i].id==provinceId')
					if(lists[i].id==provinceId){
						getcity()
						htmls+='<option selected = "selected" value="'+lists[i].id+'">'+lists[i].name+'</option>'
					}else{
						htmls+='<option value="'+lists[i].id+'">'+lists[i].name+'</option>'
					}
				 }
				 $('#provincedata').append(htmls)
			}else{

			}
		}
	});
}
// 通过省份查询市
function getcity(){
	var id=$("#provincedata").val()||provinceId
	console.log(id,'getcity')
	if(id){
		var urls =''+site.gateUrl+'/back/areaManagement/selectAreaCityByProvinceId'
		request({
			url:urls ,
			data:{provinceId:id},
			ajaxform:true,
			type: 'post',
			callback: function(r) {
				if(r.code=="rest.success"){
					var lists = r.result;
					var htmls = '';
					for (let i = 0; i < lists.length; i++) {
						console.log(lists[i].id,cityId,'lists[i].id==cityId')
						if(lists[i].id==cityId){
							htmls+='<option selected = "selected" value="'+lists[i].id+'">'+lists[i].name+'</option>'
							getArea()
						}else{
							htmls+='<option value="'+lists[i].id+'">'+lists[i].name+'</option>'
						}
							
					}
					$('#citydata').append(htmls)
				}else{

				}
			}
		});
	}
	
}
//通过市查询区县
function getArea(){
	var id=$("#citydata").val()||cityId
	if(id){
		var urls =''+site.gateUrl+'/back/areaManagement/selectAreaDistrictByCityId'
		request({
			url:urls ,
			data:{cityId :id},
			ajaxform:true,
			type: 'post',
			callback: function(r) {
				if(r.code=="rest.success"){
					var lists = r.result;
					var htmls = '';
					for (let i = 0; i < lists.length; i++) {
						if(lists[i].id==districtId){
							htmls+='<option selected = "selected" value="'+lists[i].id+'">'+lists[i].name+'</option>'
						}else{
							htmls+='<option value="'+lists[i].id+'">'+lists[i].name+'</option>'
						}
					}
					$('#districtId').append(htmls)
				}else{

				}
			}
		});
	}
}